var serialNumber = hardware.STB.serialNumber;
var caserialNumber =  CA.card.serialNumber;
EVM.cookie.setValue('serialNumber',serialNumber)
EVM.cookie.setValue('caserialNumber',caserialNumber)
var loginStatus = '';
var backurl = getParms(backurl);
// function doBack(){

//     if (typeof(Android) != "undefined") {
//         //tvos版本
//         iPanel.eventFrame.openPortal();
//     } else{
//         //中间件版本
//            window.location.href = "http://10.65.255.6:8080/portalrouting/pr.do?stbid=" + hardware.STB.serialNumber;
//     }

// }
function modelInit() {
    //面包屑
    
    if (modelIndex.crumbs) {
        TV.structure(modelIndex.crumbs)
    }
    $.cookie('TV_CST_userName', '小王', {
        expires: 7
    });
    var indexList = new TV.CookieOpt().getOpt()
    // console.log(modelIndex.disHeader, 'modelIndex.disHeader')
    var index = indexList && typeof indexList.index == 'number' ? indexList.index : undefined;
    if (!modelIndex.disUser) {
        // loginStatus = TV.UserMess()
    }
    right.toggleFocus(index);
}
/*
 * 1.右侧区
 */

cmsIndex.modules[cmsIndex.moduleGuid(cmsIndex.addModule())] = {
    modName: 'right',
    modNum: cmsIndex.moduleGuid(),
    map: {
        left: 0
    }
};

var right = cmsIndex.modules[cmsIndex.moduleGuid()].module = (function () {
    var mod = {
        modName: "index",
        modNum: cmsIndex.moduleGuid()
    },
        index = modelIndex.index, //位置
        listName = modelIndex.listName,  //模块名
        containerId = modelIndex.containerId; //包含模块的标签id

    //操作
    mod.toggleFocus = function (number) {
        var me = mod;
        if (number != undefined) {
            index = number;
        }
        TV.IndexOpt(containerId, listName, index);
        if(index==0){
            document.getElementById('pre').style.backgroundImage = "url('./images/enterQuestion_active.png')";
            document.getElementById('next').style.backgroundImage = "url('./images/record.png')";
            
            document.getElementById('model1').style.backgroundImage="url('./images/title_bg_active.png')";
            document.getElementById('model2').style.backgroundImage="url('./images/title2.png')";
            document.getElementById('model3').style.backgroundImage="url('./images/title2.png')";
            document.getElementById('model4').style.backgroundImage="url('./images/tt_back_active.png')";
        }else if(index==1){
            document.getElementById('pre').style.backgroundImage = "url('./images/enterQuestion.png')";
            document.getElementById('next').style.backgroundImage = "url('./images/record_active.png')";
        
            document.getElementById('model1').style.backgroundImage="url('./images/title2.png')";
            document.getElementById('model2').style.backgroundImage="url('./images/title_bg_active.png')";
            document.getElementById('model3').style.backgroundImage="url('./images/title2.png')";
            document.getElementById('model4').style.backgroundImage="url('./images/tt_back.png')";
        }else if(index==2){
            document.getElementById('model1').style.backgroundImage="url('./images/title2.png')";
            document.getElementById('model2').style.backgroundImage="url('./images/title2.png')";
            document.getElementById('model3').style.backgroundImage="url('./images/title_bg_active.png')";
            document.getElementById('model4').style.backgroundImage="url('./images/tt_back.png')";
        }else if (index==3){
            document.getElementById('model1').style.backgroundImage="url('./images/title2.png')";
            document.getElementById('model2').style.backgroundImage="url('./images/title2.png')";
            document.getElementById('model3').style.backgroundImage="url('./images/title2.png')";
            document.getElementById('model4').style.backgroundImage="url('./images/tt_back_active.png')";
        }
        return me;
    };

    //index 位置调整
    mod.moveOp = function (directive) {
        var me = mod;
        index = direOpt(index, directive);
        mod.toggleFocus();
        return me;
    };
    mod.action = function (directive) {
        var me = mod;
        switch (directive) {
            case 'back':

                    if (!backurl) {
                        window.location.href = "./index.html"
                        // window.location.href = "./record.html"
                    } else {
                        window.location.href = decodeURIComponent(backurl)
                    }
                    break;



                // doBack();

                // return 0;
                // if (modelIndex.isVideo && mp) {
                //     mp.stop();
                // }
                // if (modelIndex.isIndex) {
                //     window.close();
                // } else {
                //     history.go(-1);
                // }

                // break;
            case 'enter':
                if (modelIndex.isVideo && mp) {
                    mp.stop();
                }
                if (isCache) {
                    var cookieTv = new TV.CookieOpt({
                        index: index
                    })
                    var indexList = cookieTv.setOpt();
                }
                if (index == -1) {
                    if (loginStatus) {
                        if (modelIndex.isIndex) {
                            window.location.href = './pages/user.html'
                        }
                        else {
                            window.location.href = '../pages/user.html'
                        }
                    } else {
                        if (modelIndex.isIndex) {
                            window.location.href = './pages/login.html'
                        } else {
                            window.location.href = '../pages/login.html'
                        }
                    }

                } else if (index >= 0) {

                    direEnter(index);

                }
                break;
        }
        return me;
    };
    mod.grabEvent = function (key) {
        var me = mod;
        var keyJson = TV.GetKey(key);
        if (keyJson.keyState && keyJson.keyState != 'enter' && keyJson.keyState != 'back') {
            me.moveOp(keyJson.keyState);
        } else {
            me.action(keyJson.keyState)
        }
        return keyJson.isBlock;


    };

    return mod;
})();

cmsIndex.run();
